package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.dto.GoodsSalesDTO;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.entity.Orders;
import com.sky.vo.OrderStatisticsVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

@Mapper
public interface OrderMapper {
    void insert(Orders order);

    // 根据订单号查询订单
    @Select("select * from orders where number = #{orderNumber}")
    Orders getByNumber(String orderNumber);

    void update(Orders orders);

    Page<Orders> pageQuery(OrdersPageQueryDTO ordersPageQueryDTO);

    // 根据订单id查询订单
    @Select("select * from orders where id = #{id}")
    Orders getById(Long id);

    // 查询某一状态下的订单数量
    @Select("select count(id) from orders where status = #{status}")
    Integer countStatus(Integer status);

    // 根据订单状态和截止时间查询订单信息
    @Select("select * from orders where status = #{status} and order_time < #{timeout}")
    List<Orders> getByStatusAndTimeout(Integer status, LocalDateTime timeout);

    // 查询每日的营业额
    Double sumByMap(Map map);

    // 查询每日的订单数量
    Integer countByMap(Map map);
    // 查询时间区间内的销量排名前10的商品
    List<GoodsSalesDTO> getSalesTop10(Map map);
}
